package com.bamboo.framework.framework.security.util;

import com.bamboo.framework.framework.security.entity.User;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * Security工具类
 */
public class SecurityUtil {
    /**
     * 获取当前用户
     * @return 获取当前用户信息
     */
    public static User getCurrentUser() {
        return (User) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
    }

    /**
     * 获取当前用户id
     * @return 当前用户id
     */
    public  static  String getUserId(){
        return String.valueOf(getCurrentUser().getId()).toString() ;
    }
}
